<?php
$phonelist=array("fb9b73e6","605f3f54","ad0a3658","88e2b36c","b947a798","dc79b4bf","f2cf7a9c","8c53898","13639518","ac58e541","4b55a6a9","32de6b26","c43e4ef9","3e4abe36","890fcd00","1a8ea15d","1ce7befa","MYVDU16105001388","QW4HZDLBW495YPAY","91QEBNM2CB2L","HT3AKW9A0489","RF1F51C6TZX","RF1D46SR2FR","WUJ01K8178","E7AZCY608114","HT539YC00473","022BTF7N37087294","1274f0b","HC4B1WME0029");
$cameralist=array("99997872","997872","99996918","99997894","99997875","99998808","99997782","997877","99997992","99998883","99997784","99999918","99998892","99998881","99998791","99998882","99997788","99997998","99997798","99997789","99999836","00000053","999837","999841","99999840","SV1-000088","SV1-999837","SV1-999821","SV1-999982","SV1-999923","99999982","99999923","99998890","99997791","99997792","99998888","99999836","99997779","99997778");
if (empty($_POST["software_version_code"]) && empty($_POST["hardware_version_code"]) && empty($_POST["remoterware_version_code"])){
  echo '{"rval":1}';//参数为空
  exit;
}
$softcode_test="1.3.4.10520";
$softcode_test="1.5.7.11350";
// $softcode_content="V".$softcode_test." ［最近更新］1.适配相机wifi、2.新增相机过热保护提示功能...";
$softcode_content="V".$softcode_test." ［最近更新］1.首页相册模块布局2.详情页面添加评论功能...";
$softcode_content="1.首页相册模块布局2.详情页面添加评论功能...";

$softcode_publish="1.5.1.10615";
if(in_array($_POST["IMEI"],$phonelist)){
  if (!empty($_POST["software_version_code"])){
    $ss1=implode("",explode(".",$_POST["software_version_code"]));
    $ss2=implode("",explode(".",$softcode_test));
    if($ss1<$ss2){
      $soft='{"version_code":"'.$ss2.'","version_name":"'.$softcode_test.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/android/app-V'.$softcode_test.'.apk","content":"'.$softcode_content.'"}';
    }else{
      $soft="{}";
    }
  }else{
    //echo '{"rval":2}';//最新版本
    $soft="{}";
  }
}else{
  if (!empty($_POST["software_version_code"])){
    $ss1=implode("",explode(".",$_POST["software_version_code"]));
    $ss2=implode("",explode(".",$softcode_publish));
    if($ss1<$ss2){
      $soft='{"version_code":"'.$ss2.'","version_name":"'.$softcode_publish.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/android/app-V'.$softcode_publish.'.apk","content":"'.$softcode_content.'"}';
      //$soft='{"version_code":17,"version_name":"'.$softcode_publish.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/madv360/app-V'.$softcode_publish.'.apk","content":"'.$softcode_publish.'"}';
    }else{
      $soft="{}";
    }
  }else{
    //echo '{"rval":2}';//最新版本
    $soft="{}";
  }
}
// $hardcode_test="1.3.85.71.5.11448";
$hardcode_test="1.3.85.70.5.11443";
$hardcode_content="【文件17MB】删除录像时对参数区域的保存,减少写NAND的次数...";
$hardcode_publish="1.3.78.46.5.10025";
if($_POST["SID"]=="99999836zhangqiaoge"){
  $hard='{"version_code":"12663358646","version_name":"1.2.66.33.5.8646","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/madv360/a12_fw_for_upgrade_1.2.66.33.5.8646.devfw","content":"巧隔专用测试"}';
}else{
if(in_array($_POST["SID"],$cameralist)){
  if (!empty($_POST["hardware_version_code"])){
    $ss1=implode("",explode(".",$_POST["hardware_version_code"]));
    $ss2=implode("",explode(".",$hardcode_test));
    if($ss1<$ss2){
      $hard='{"version_code":"'.$ss2.'","version_name":"'.$hardcode_test.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/hard/a12_fw_for_upgrade_'.$hardcode_test.'.zip","content":"'.$hardcode_content.'"}';
    }else{
      $hard="{}";
    }
  }else{
    $hard="{}";
    //echo '{"rval":2}';//最新版本
  }
}else{
  if (!empty($_POST["hardware_version_code"])){
    $ss1=implode("",explode(".",$_POST["hardware_version_code"]));
    $ss2=implode("",explode(".",$hardcode_publish));
    if($ss1<$ss2){
      $hard='{"version_code":"'.$ss2.'","version_name":"'.$hardcode_publish.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/madv360/a12_fw_for_upgrade_'.$hardcode_publish.'.devfw","content":"'.$hardcode_content.'"}';
    }else{
      $hard="{}";
    }
  }else{
    $hard="{}";
    //echo '{"rval":2}';//最新版本
  }
}
}
//126
$remoter_test="130";
$remoter_content="1";
$remoter_publish="1";
if(in_array($_POST["SID"],$cameralist)){
  if (!empty($_POST["remoterware_version_code"])){
    $ss1=implode("",explode(".",$_POST["remoterware_version_code"]));
    $ss2=implode("",explode(".",$remoter_test));
    if($ss1<$ss2){
      $remoter='{"version_code":"'.$ss2.'","version_name":"'.$remoter_test.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/remoterware/rc_firmware.bin.'.$remoter_test.'","content":"'.$remoter_content.'"}';
    }else{
      $remoter="{}";
    }
  }else{
    $remoter="{}";
    //echo '{"rval":2}';//最新版本
  }
}else{
  if (!empty($_POST["remoterware_version_code"])){
    $ss1=implode("",explode(".",$_POST["remoterware_version_code"]));
    $ss2=implode("",explode(".",$remoter_publish));
    if($ss1<$ss2){
      $remoter='{"version_code":"'.$ss2.'","version_name":"'.$remoter_publish.'","download_url":"https://cdn.awsbj0.fds.api.mi-img.com/madv360/rc_firmware.bin.'.$remoter_publish.'","content":"'.$remoter_content.'"}';
    }else{
      $remoter="{}";
    }
  }else{
    $remoter="{}";
    //echo '{"rval":2}';//最新版本
  }
}
if(!empty($soft) && $soft!="{}"){
  $output='{"rval":0, "result":{"soft":'.$soft;
  if(!empty($hard) && $hard!="{}"){
    $output.=',"hard":'.$hard.',"remoter":'.$remoter.'}}';
  }else{
    $output.='}}';
  }
}else{
  $output='{"rval":0, "result":{';
  if(!empty($hard) && $hard!="{}"){
    $output.='"hard":'.$hard.',"remoter":'.$remoter.'}}';
  }else{
    $output.='}}';
  }
}
echo '{"rval":0, "result":{"soft":'.$soft.',"hard":'.$hard.',"remoter":'.$remoter.'}}';
